home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
util
/
dir
/
Drawersize.lha
/
Drawersize
/
Drawersize.bb2
< prev
next >
Wrap
Text File
|
1999-01-17
|
9KB
|
336 lines
;*******************************************************************
; *
;DrawerSize.bb2 *
; *
;Program to attach a menu item to WB Tools menu which finds the *
;size of a drawer, its subdrawers and files and displays *
;no. of bytes on WBScreen title bar. Runs from WBStartup drawer. *
; *
;Written in Blitz Basic II *
; *
;Fully working prototype! 5/10/94 *
;Finished (?) by HVB, SPR 25/10/94 *
;(Made compatible with WB prefs 26/2/95) not relevant to this ver. *
;Cured a particularly elusive and fatal bug 17/3/95 *
;Made into a commodity 17/4/95 *
; *
;Replaced custom titlebar output with ShowTitle_ (again!) 28/3/97 *
; *
;amigalibs.res resident using Compiler Options *
; (must be the LATEST, ie 3.0!!!) *
; *
;*******************************************************************
;system structure defs. Thank God for amigalibs.res!
DEFTYPE.MsgPort *wb_port, *cx_port
DEFTYPE.AppMessage *appmsg
DEFTYPE.FileInfoBlock *fib
DEFTYPE.Screen *wbscreen
DEFTYPE.NewBroker newbroker
DEFTYPE.l appitem, cx_msgid, *broker
title$ = "Select Drawer icon(s) for size in bytes." ;initial message
user_data$ = "C:Command"
amItem$ = "Drawer Size"
cx_name$ = "DrawerSize"
cx_title$ = "DrawerSize (C) H Brown, S Rouse 1995"
cx_descr$ = "Finds size of drawer & files in bytes."
wbscreenname$ = "Workbench"
NUL.l = 0
total.l = 0
quit_prog = False
enabled = True
;*****************************************************************
;
;Functions
;
;*****************************************************************
;-----------------------------------------------------------------
; GetSize{path$} ;idea pinched from WhereIs by Paul Andrews
;
; This is a recursive statement. Work it out for yourselves!
;-----------------------------------------------------------------
Statement GetSize{path$}
SHARED total,*fib ;can't use any variables from the main program
;unless they are SHAREd
lock.l=Lock_(&path$,-2)
gotFib.l=Examine_(lock,*fib)
If gotFib=0 Then Goto failed
While ExNext_(lock,*fib)<>0
;filename is stored as a char string fib_FileName
;WITHIN the fib structure (max 108 chars)
;&*fib\fib_FileName gets the address of the first
;char in the string. Peek$(&) loads n$ with the
;null terminated string starting at this address
n$ = Peek$(&*fib\fib_FileName)
n$ = LCase$(n$)
filetype.l = *fib\fib_DirEntryType
If filetype<0 ;file is not a drawer
total = total + *fib\fib_Size
EndIf
If filetype=>0 ;file is a drawer
p$=path$
If Right$(p$,1) = ":" OR Right$(p$,1) = "/"
p$=p$ + n$
Else
p$=p$ + "/" + n$
EndIf
GetSize{p$} ;HELP!!!!!!
EndIf
Wend
failed:
UnLock_ lock
End Statement
;**************************************************************
;
; Program Entry
;
;**************************************************************
WBStartup
If ExecVersion < 37 Then End ;SORRY, CHAPS!
;allocate the space for a file info block
*fib=AllocMem_(SizeOf.FileInfoBlock,#MEMF_PUBLIC|#MEMF_CLEAR)
Format "###,###,###,###"
;------------------------------------------------------------------
;Create a message port so that WB can signal when our menu selected
;------------------------------------------------------------------
*wb_port = CreateMsgPort_()
wb_PortSig.l = 1 LSL *wb_port\mp_SigBit
;-------------------------------------------------------------------
;Attach our menu item to WB Tools menu
;-------------------------------------------------------------------
appitem.l = AddAppMenuItemA_(NUL,&user_data$,&amItem$,*wb_port,NUL) ;note use of &
;-------------------------------------------------------------------
;Set up a commodity (serious stuff!)
;-------------------------------------------------------------------
*cx_port = CreateMsgPort_() ;for communicating with Commodities Exchange
cx_PortSig.l = 1 LSL *cx_port\mp_SigBit
;initialise the NewBroker structure
newbroker\nb_Version = #NB_VERSION,0,&cx_name$,&cx_title$,&cx_descr$,0,0,0,0,0,0
newbroker\nb_Port = *cx_port ;tell broker where its messageport will be
*broker = CxBroker_(&newbroker, 0) ;attach the broker to CX list
ActivateCxObj_ *broker, 1 ;switch it on
;-------------------------------------------------------------------
; MAIN PROGRAM LOOP
;-------------------------------------------------------------------
Repeat
;go to sleep and wait for messages from either port
signal.l = Wait_(wb_PortSig | cx_PortSig)
;yawn, OK what's going on?
;try the commodity port...
cx_msg.l = GetMsg_(*cx_port)
If cx_msg
Gosub proc_CX_commands
ReplyMsg_ cx_msg
EndIf
;try the appmenuitem port...
*appmsg = GetMsg_(*wb_port)
If *appmsg AND enabled
Gosub get_size
ReplyMsg_ *appmsg
EndIf
Until quit_prog = True
DeleteCxObj_(*broker)
DeleteMsgPort_(*cx_port)
RemoveAppMenuItem_(appitem)
DeleteMsgPort_(*wb_port)
FreeMem_ *fib, SizeOf.FileInfoBlock
End
;**************************************************************
; subroutines
;**************************************************************
;-------------------------------------------------------------
;The Code!? ;(this is a very old comment, kept for posterity)
;-------------------------------------------------------------
get_size
*wbscreen = LockPubScreen_(&wbscreenname$)
UnlockPubScreen_ NUL, *wbscreen
newdrawerflag = 0
For icon_number = 0 To *appmsg\am_NumArgs-1 ;group select!
Gosub GetDrawerPath ;get full path of drawer, returned in dpath$
If good.l = 1 ;icon is a drawer
total = 0
GetSize{dpath$}
title$ = StripTrail$(dpath$,47) + " " + StripLead$(Str$(total),32) + " Bytes"
; (remove trailing /) (remove leading spaces added by Format statement)
Else
;good <> 1, icon is not a drawer
title$ = "Not a Drawer icon"
DisplayBeep_ 0
EndIf
*wbscreen\Title = &title$
ShowTitle_ *wbscreen, -1
;reset default output if not a drawer icon
If good.l <> 1 Then title$ = "Select Drawer icon(s) for size in bytes."
newdrawerflag = 1
Next icon_number
;choose message if no icon selected
If newdrawerflag = 0
If Left$(title$,6) = "Select"
*wbscreen\Title = &title$
ShowTitle_ *wbscreen, -1
Else
output$ = "Last selected: " + title$
*wbscreen\Title = &output$
ShowTitle_ *wbscreen, -1
EndIf
EndIf
Return
;---------------------------------------------------------------
proc_CX_commands ;Act on commands from Commodities Exchange
;---------------------------------------------------------------
msgid = CxMsgID_(cx_msg) ;no need to get msgtype: no input events!!
Select msgid
Case #CXCMD_DISABLE
If enabled = True
enabled = False
RemoveAppMenuItem_(appitem)
ActivateCxObj_ *broker, 0
EndIf
Case #CXCMD_ENABLE
If enabled = False
enabled = True
appitem = AddAppMenuItemA_(NUL,&user_data$,&amItem$,*wb_port,NUL)
ActivateCxObj_ *broker, 1
EndIf
Case #CXCMD_KILL
enabled = False
quit_prog = True
End Select
Return
;---------------------------------------------------------------
GetDrawerPath ;(by Aaron Koolen, BUM7)
;---------------------------------------------------------------
dpath$=""
args.l = *appmsg\am_ArgList + (icon_number * SizeOf.WBArg)
lock.l = Peek.l(args) ; Lock of parent!
name$ = Peek$(Peek.l(args+4)) ; Name of icon
; Get info about the file
good.l = Examine_(lock,*fib)
If good<>0
dpath$=Peek$(&*fib\fib_FileName)
; Make the entire pathname for the file
Repeat
lock=ParentDir_(lock)
If lock
If Examine_(lock,*fib)
dpath$=dpath$+"/"+name$
name$=dpath$
dpath$= Peek$(&*fib\fib_FileName)
EndIf
EndIf
Until lock=0
dpath$=dpath$+":"+name$
; Examine this name to check if it's a directory or not!
lock.l=Lock_(dpath$,-2)
If lock
If Examine_(lock,*fib)
If *fib\fib_DirEntryType>0
good = 1 : dirLock.l = lock
d$=dpath$
EndIf
EndIf
UnLock_ lock
lock=0
EndIf
EndIf
Return